package cn.xxi.ai.application.dto;

import cn.xxi.ai.application.entity.MessageData;
import lombok.Getter;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

@Getter
public abstract class FinishedEvent extends MessageData {

    /** 状态 */
    protected final Status status;

    /** 错误信息 */
    protected final String error;

    /** 开始时间 */
    protected final LocalDateTime startedAt;

    /** 结束时间 */
    protected final LocalDateTime finishedAt;

    /** 耗时，毫秒 */
    protected final long elapsedTime;

    public FinishedEvent(Status status, String error, LocalDateTime startedAt) {
        this.status = status;
        this.error = error;
        this.startedAt = startedAt;
        this.finishedAt = LocalDateTime.now();
        this.elapsedTime = ChronoUnit.MILLIS.between(startedAt, finishedAt);
    }
}
